package com.sxt.demo.djiapplication.entity;


import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Keep;
import org.greenrobot.greendao.annotation.Property;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.DaoException;
import com.sxt.demo.djiapplication.dao.DaoSession;
import com.sxt.demo.djiapplication.dao.WayPointRecordItemDao;
import com.sxt.demo.djiapplication.dao.WayPointRecordDao;

@Entity(nameInDb = "way_point_record")
public class WayPointRecord {

    @Id(autoincrement = true)
    @Property(nameInDb = "id")
    private Long id;

    @Property(nameInDb = "title")
    private String title;

    @Property(nameInDb = "record_time")
    private String recordTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.CHINA)
            .format(new Date(System.currentTimeMillis()));

    @ToMany(referencedJoinProperty = "recordId")
    private List<WayPointRecordItem> wayPointRecordItems;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 2048739558)
    private transient WayPointRecordDao myDao;

    @Generated(hash = 1891753379)
    public WayPointRecord(Long id, String title, String recordTime) {
        this.id = id;
        this.title = title;
        this.recordTime = recordTime;
    }

    @Keep
    public WayPointRecord(String title, String recordTime) {
        this.title = title;
        this.recordTime = recordTime;
    }

    @Keep
    public WayPointRecord(String title) {
        this.title = title;
    }

    @Generated(hash = 41429316)
    public WayPointRecord() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getRecordTime() {
        return this.recordTime;
    }

    public void setRecordTime(String recordTime) {
        this.recordTime = recordTime;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 843172666)
    public List<WayPointRecordItem> getWayPointRecordItems() {
        if (wayPointRecordItems == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            WayPointRecordItemDao targetDao = daoSession.getWayPointRecordItemDao();
            List<WayPointRecordItem> wayPointRecordItemsNew = targetDao
                    ._queryWayPointRecord_WayPointRecordItems(id);
            synchronized (this) {
                if (wayPointRecordItems == null) {
                    wayPointRecordItems = wayPointRecordItemsNew;
                }
            }
        }
        return wayPointRecordItems;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1507374325)
    public synchronized void resetWayPointRecordItems() {
        wayPointRecordItems = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 59641072)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getWayPointRecordDao() : null;
    }

}
